package com.lanou3g.dllo.baidumusic.musiclibrary.recommend.allsingerdetail;


import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.lanou3g.dllo.baidumusic.R;
import com.lanou3g.dllo.baidumusic.base.BaseFragment;
import com.lanou3g.dllo.baidumusic.base.MyApp;

import com.lanou3g.dllo.baidumusic.main.MainActivity;
import com.lanou3g.dllo.baidumusic.tools.MyVolley;
import com.lanou3g.dllo.baidumusic.urlvalues.UrlValues;

/**
 * Created by dllo on 16/6/27.
 */
public class AllSingerDetailFragment extends BaseFragment {

    private AllSingerDetailAdapter allSingerDetailAdapter;
    private ListView allSingerDetailListView;
    private TextView allsingerDetailAllcountrysinger;
    private ImageView singerDetailReturnBtn;
    private AllSingerDetailBean allSingerDetailBean;

    @Override
    public int setLayout() {
        return R.layout.fragment_allsingerdetail;
    }

    @Override
    public void initView(View view) {

        allSingerDetailAdapter = new AllSingerDetailAdapter(MyApp.context);
        singerDetailReturnBtn = (ImageView) view.findViewById(R.id.allsingerdetail_return_btn);
        allSingerDetailListView = (ListView) view.findViewById(R.id.allsingerdetail_listview);
        allSingerDetailListView.setAdapter(allSingerDetailAdapter);
        allsingerDetailAllcountrysinger = (TextView) view.findViewById(R.id.allsingerdetail_allcountrysinger);
        // 返回键右边的textView设置文字
        String text = this.getArguments().getString("type");
        allsingerDetailAllcountrysinger.setText(text);
        allSingerDetailBean = new AllSingerDetailBean();
    }

    @Override
    public void initData() {
        // 返回
        singerDetailReturnBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ((MainActivity)getActivity()).finishNew();
            }
        });

        String url = this.getArguments().getString("url");
        MyVolley.getMyVolley().initGson(url, new MyVolley.GetGsonListener<AllSingerDetailBean>() {
            @Override
            public void getGsonListener(AllSingerDetailBean data) {
                allSingerDetailBean = data;
                allSingerDetailAdapter.setAllSingerDetailBean(data);
            }

        }, AllSingerDetailBean.class);
        // 监听,回调
        allSingerDetailListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                MainActivity mainActivity = (MainActivity) getActivity();
                String tingUid = allSingerDetailBean.getArtist().get(position).getTing_uid();
                String pictureUrl = allSingerDetailBean.getArtist().get(position).getAvatar_big();
                mainActivity.toSingerDetail(UrlValues.SINGER_DETAIL_BEFORE + tingUid + UrlValues.SINGER_DETAIL_BEHIDE, tingUid,pictureUrl);
            }
        });

    }
}
